﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using BLL;
using DAL;
using Table_Dal;
namespace ApplicationLayer
{
    public partial class Manager : DevComponents.DotNetBar.RibbonForm
    {
        public Manager()
        {
            InitializeComponent();
        }
        string User = "";
        public Manager(string str)
        {
            User = str;
            
            InitializeComponent();
        }
        int PQ;
        
        private void Manager_Load(object sender, EventArgs e)
        {
            QuantriBll qt = new QuantriBll();
            PQ = qt.PhanQuyen(User);
            if (PQ == 0)
            {
                //la Admin
                pnlAdmin.Visible = true;
            }
            lbl_User.Text = User;
          
            Home();
        }
        public void Home(){

            frmCaNhan cn = new frmCaNhan(User);
            //frmRaDeGiaiThuat cn = new frmRaDeGiaiThuat();
            CloseForm(cn);
            ShowForm(cn);
            
        }
       
        private void ShowForm(Form f)
        {
            bool thay = false;
            foreach (Form frm in this.MdiChildren)
            {
                if (frm.Name.ToUpper().Equals(f.Name.ToUpper()))
                {
                    frm.Activate();
                    thay = true;
                }
            }
            if (thay == false)
            {
                f.MdiParent = this;
                f.Show();
            }
        }
        
        
        private void btnThoat_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn muốn thoát chương trình này ?", "Thông báo", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                Application.Exit();
            }
            
        }

        private void btnDangXuat_Click(object sender, EventArgs e)
        {
            
        
        }

        private void btnThongTin_Click(object sender, EventArgs e)
        {
            frmCaNhan cn = new frmCaNhan(User);
            CloseForm(cn);
            ShowForm(cn);
            
        }

        private void cboxLang_SelectedIndexChanged_1(object sender, EventArgs e)
        {
           
          
        }

        private void cboxLang_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void btnHome_Click(object sender, EventArgs e)
        {
            frmCaNhan cn = new frmCaNhan(User);
            CloseForm(cn);
            ShowForm(cn);
            
        }
        public void CloseForm(Form form_hienthoi)
        {
            foreach (Form frm in this.MdiChildren)
            {
                if (!frm.Equals(form_hienthoi))
                    frm.Close();
            }
        }
        private void btnCauHoi_Click(object sender, EventArgs e)
        {
            frmCauHoi frm = new frmCauHoi(User);
            CloseForm(frm);
            ShowForm(frm);
            
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {
            
            
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            DialogResult = MessageBox.Show("Bạn muốn thoát khỏi user: " + User + " này ?", "Thông báo", MessageBoxButtons.YesNo);
            if (DialogResult == DialogResult.Yes)
            {
                LogIn lgIn = new LogIn();
                this.Hide();
                lgIn.Show();
            }
        }
           
        private void BtnDeThi_Click(object sender, EventArgs e)
        {
            frmDeThi frm = new frmDeThi(User);
            CloseForm(frm);
            ShowForm(frm);
            
        }

        private void btnMonHoc_Click(object sender, EventArgs e)
        {
            frmMonHoc frm = new frmMonHoc();
            CloseForm(frm);
            ShowForm(frm);
        }

        private void btnGiangvien_Click(object sender, EventArgs e)
        {
            frmNguoiRaDe frm = new frmNguoiRaDe(PQ);
            CloseForm(frm);
            ShowForm(frm);
        }

        private void btnThiSInh_Click(object sender, EventArgs e)
        {
            ThiSinh.frmThiSinh frm = new ThiSinh.frmThiSinh();
            CloseForm(frm);
            ShowForm(frm);
        }

    }
}